python爬虫爬取微博热搜 |
您所在的位置:网站首页 › python爬虫 爬取资料 › python爬虫爬取微博热搜 |
【实例简介】 【实例截图】
【核心代码】 import requests #数据抓取库 from lxml import etree #数据解析库 import time #内置函数,时间库 #时间格式化 today = time.strftime( '%Y{y}%m{m}%d{d}',time.localtime()).format(y='年',m='月',d='日') print(today) #数据抓取 url = "https://s.weibo.com/top/summary?cate=realtimehot" #热搜地址 headers ={ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.60" } #headers伪装头 response = requests.get(url,headers=headers) #发送请求 #print(response.text) #获取html源码 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |